﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace xna_game_engine.source
{
    public class EventManager
    {
        // Members
        public enum Events
        {
            EVT_START_HIT = 0,
            //EVT_ENTER_HIT,
            EVT_A_HIT,
            EVT_B_HIT,
            EVT_Y_HIT,
            EVT_SELECT_HIT,
            EVT_R_BUMPER_HIT,
            EVT_L_BUMPER_HIT,
            EVT_L_TRIGGER_HIT,
            EVT_R_TRIGGER_HIT,
        };

        //public Dictionary<Keys, Events> mEventMap;

        // Functions
        //public EventManager()
        //{
        //    mEventMap = new Dictionary<Keys, Events>();
        //    mEventMap.Add(Keys.P, Events.EVT_START_HIT);
        //    mEventMap.Add(Keys.Enter, Events.EVT_ENTER_HIT);
        //    mEventMap.Add(Keys.A, Events.EVT_A_HIT);
        //    mEventMap.Add(Keys.B, Events.EVT_B_HIT);
        //    mEventMap.Add(Keys.S, Events.EVT_SELECT_HIT);
        //}

        public Dictionary<Buttons, Events> mEventMap;

        // Functions
        public EventManager()
        {
            mEventMap = new Dictionary<Buttons, Events>();
            mEventMap.Add(Buttons.Start, Events.EVT_START_HIT);
            //mEventMap.Add(Keys.Enter, Events.EVT_ENTER_HIT);
            mEventMap.Add(Buttons.A, Events.EVT_A_HIT);
            mEventMap.Add(Buttons.B, Events.EVT_B_HIT);
            mEventMap.Add(Buttons.Y, Events.EVT_Y_HIT);
            mEventMap.Add(Buttons.Back, Events.EVT_SELECT_HIT);
            mEventMap.Add(Buttons.RightShoulder, Events.EVT_R_BUMPER_HIT);
            mEventMap.Add(Buttons.LeftShoulder, Events.EVT_L_BUMPER_HIT);
            mEventMap.Add(Buttons.LeftTrigger, Events.EVT_L_TRIGGER_HIT);
            mEventMap.Add(Buttons.RightTrigger, Events.EVT_R_TRIGGER_HIT);
        }

        public void Update(GameTime gameTime)
        {
            //foreach (KeyValuePair<Keys, Events> pair in mEventMap)
            //{
            //    if (GameSystems.Input.CheckKeyPress(pair.Key))
            //    {
            //        Console.WriteLine("Event Dispatched");
            //        DispatchEvent(pair.Value);
            //    }
            //}

            foreach (KeyValuePair<Buttons, Events> pair in mEventMap)
            {
                if (GameSystems.Input.CheckButtonPress(pair.Key))
                {
                    Console.WriteLine("Event Dispatched");
                    DispatchEvent(pair.Value);
                }
            }
        }

        public void DispatchEvent(Events ev)
        {
            GameGlobals.StateMachine.HandleEvent(ev);
        }
    }
}
